package main

import (
	"bytes"
	"crypto/aes"
	"fmt"
)

func main() {
	aes_key := "!@#$%^&*FJGFJT78"
	account := "1595175752715951757527"
	// 8d6560f31221e280e240bdcc8d183e73
	block, _ := aes.NewCipher([]byte(aes_key))
	data := PKCS5Padding([]byte(account), block.BlockSize())
	if len(data)%block.BlockSize() != 0 {
		// 由于下面会对块进行加密，每一块的大小是 blockSize 的大小。如果不是整数倍的话则报错
		panic("crypto/cipher: input not full blocks")
	}

	out := make([]byte, len(data))
	dst := out
	for len(data) > 0 {
		// 对每一块加密处理
		//对明文按照blocksize进行分块加密
		//必要时可以使用go关键字进行并行加密
		block.Encrypt(dst, data[:block.BlockSize()])
		data = data[block.BlockSize():]
		dst = dst[block.BlockSize():]
	}

	fmt.Printf("%X  - \n", out)
}

func PKCS5Padding(ciphertext []byte, blockSize int) []byte {
	padding := blockSize - len(ciphertext)%blockSize
	padtext := bytes.Repeat([]byte{byte(padding)}, padding)
	return append(ciphertext, padtext...)
}
